<template>
  <div class="login-container">
    <el-row :gutter="20" class="header">
      <el-col :span="5" :offset="4">
        <img
          class="bannerimg"
          src="../../../assets/images/bg.jpg"
          alt="123 "
        />
      </el-col>
      <el-col :span="10">
        <h1 class="websitename">新型冠状病毒防控及疾病检测系统 </h1>
      </el-col>
    </el-row>

    <img class="bgimg" src="../../../assets/images/show.jpeg" alt="" />
    <div class="loginblock login-form">
      <el-carousel :autoplay="false" indicator-position="none">
        <el-carousel-item>
          <el-form
            autoComplete="on"
            :model="loginForm"
            :rules="loginRules"
            ref="loginForm"
            label-position="left"
            label-width="0px"
            class="card-box"
          >
            <h3 class="title">欢迎您回来，医生</h3>
            <el-form-item prop="name">
              <span class="svg-container svg-container_login">
                <svg-icon icon-class="user" />
              </span>
              <el-input
                name="name"
                type="text"
                v-model="loginForm.name"
                autoComplete="on"
                placeholder="name"
              />
            </el-form-item>
            <el-form-item prop="password">
              <span class="svg-container">
                <svg-icon icon-class="password"></svg-icon>
              </span>
              <el-input
                name="password"
                :type="pwdType"
                @keyup.enter.native="handleLogin"
                v-model="loginForm.password"
                autoComplete="on"
                placeholder="password"
              ></el-input>
              <span class="show-pwd" @click="showPwd"
              ><svg-icon icon-class="eye"
              /></span>
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                style="width: 100%"
                :loading="loading"
                @click.native.prevent="handleLogin"
              >
                登 录
              </el-button>
            </el-form-item>
          </el-form>
        </el-carousel-item>

<!--        注册-->
        <el-carousel-item >
          <el-form
            autoComplete="on"
            :model="loginForm"
            :rules="loginRules"
            ref="loginForm"
            label-position="left"
            label-width="0px"
            class="card-box"
          >
            <h3 class="title">您好，请注册</h3>
            <el-form-item prop="name">
              <span class="svg-container svg-container_login">
                <svg-icon icon-class="user" />
              </span>
              <el-input
                name="name"
                type="text"
                v-model="loginForm.name"
                autoComplete="on"
                placeholder="name"
              />
            </el-form-item>
            <el-form-item prop="password">
              <span class="svg-container">
                <svg-icon icon-class="password"></svg-icon>
              </span>
              <el-input
                name="password"
                :type="pwdType"
                @keyup.enter.native="handleRegist"
                v-model="loginForm.password"
                autoComplete="on"
                placeholder="password"
              ></el-input>
              <span class="show-pwd" @click="showPwd"
              ><svg-icon icon-class="eye"
              /></span>
            </el-form-item>
            <el-form-item >
              <el-select v-model="loginForm.hid" placeholder="请选择医院">
                <el-option
                  v-for="item in hosptiallist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item >
              <el-input
                name="subject"
                v-model="loginForm.subject"
                placeholder="科室"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button
                type="success"
                style="width: 100%"
                :loading="loading"
                @click.native.prevent="handleRegist"
              >
                注 册
              </el-button>
            </el-form-item>
          </el-form>
        </el-carousel-item>
      </el-carousel>
    </div>
    <vue-particles
      class="bg"
      color="#dedede"
      :particleOpacity="0.7"
      :particlesNumber="80"
      shapeType="circle"
      :particleSize="4"
      linesColor="#dedede"
      :linesWidth="1"
      :lineLinked="true"
      :lineOpacity="0.4"
      :linesDistance="150"
      :moveSpeed="3"
      :hoverEffect="true"
      hoverMode="grab"
      :clickEffect="true"
      clickMode="push"
    >
    </vue-particles>
  </div>
</template>

<script>
  import { login, logout,regist,getHosptialAll } from "@/api/doctor";
  export default {
    name: "login",
    data() {
      const validatename = (rule, value, callback) => {
        callback();
      };
      const validatePass = (rule, value, callback) => {
        if (value.length < 5) {
          callback(new Error("密码不能小于5位"));
        } else {
          callback();
        }
      };
      return {
        hosptiallist:[],
        loginForm: {
          name: "doctor",
          password: "123123",
        },
        loginRules: {
          name: [{ required: true, trigger: "blur", validator: validatename }],
          password: [
            { required: true, trigger: "blur", validator: validatePass },
          ],
        },
        loading: false,
        pwdType: "password",
      };
    },
    created() {
      this.gethosptial();
    },
    methods: {
      showPwd() {
        if (this.pwdType === "password") {
          this.pwdType = "";
        } else {
          this.pwdType = "password";
        }
      },
      gethosptial() {
        getHosptialAll({}).then(res=>{
          console.log(res);
          this.hosptiallist = res.info;
        })
      },
      handleLogin() {
        this.$refs.loginForm.validate((valid) => {
          if (valid) {
            login(this.loginForm)
              .then((response) => {
                localStorage.setItem("logininfo", JSON.stringify(response));
                this.loading = false;
                this.$router.push({ path: "/doctor" });
              })
              .catch((error) => {
                this.loading = false;
              });
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },
      handleRegist() {
        this.$refs.loginForm.validate((valid) => {
          if (valid) {
            regist(this.loginForm)
              .then((response) => {
                this.loading = false;
                this.$notify({type:"success",title:"成功",message:"注册成功!"})

              })
              .catch((error) => {
                this.loading = false;
              });
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },
    },
  };
</script>

<style rel="stylesheet/scss" lang="scss">
  $bg: #f15151;
  $dark_gray: #6c8ac0;
  $light_gray: rgb(250, 250, 250);
  .el-carousel__container{
    height: 400px;
  }
  .login-container {
    position: fixed;
    height: 100%;
    width: 100%;
    input:-webkit-autofill {
      -webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
      -webkit-text-fill-color: #fff !important;
    }
    .loginform {
      float: right;
      margin-right: 300px;
    }

    .header {
      width: 100%;
      height: 80px;
      padding: 10px;
      background-color: rgb(255, 255, 255);

      .bannerimg {
        height: 60px;
      }
      .websitename {
        vertical-align: center;
        color: #8a8e92;
      }
    }
    .loginblock {
    }
    .bgimg {
      position: fixed;
      left: 0;
      width: 100%;
      right: 0;
      z-index: -1;
    }
    .bgimg {
      position: fixed;
      left: 0;
      right: 0;
      z-index: -1;
    }
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
    }
    .el-input {
      display: inline-block;
      height: 47px;
      width: 85%;
    }
    .tips {
      font-size: 14px;
      color: #fff;
      margin-bottom: 10px;
    }
    .svg-container {
      padding: 6px 5px 6px 15px;
      color: $dark_gray;
      vertical-align: middle;
      width: 30px;
      display: inline-block;
      &_login {
        font-size: 20px;
      }
    }
    .title {
      font-size: 26px;
      font-weight: 400;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
    .login-form {
      float: right;
      background-color: #d42414;
      margin-right: 200px;
      margin-top: 100px;
      width: 400px;
      height: 500px;
      padding: 35px 35px 15px 35px;
    }
    .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }
    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }
    .thirdparty-button {
      position: absolute;
      right: 35px;
      bottom: 28px;
    }
  }
</style>
